<template>
	<view class="container">
		<!-- 顶部导航 -->
		<view class="header">
			<view class="header-left" @click="goBack">
				<uni-icons type="left" size="24" color="#2c3e50"></uni-icons>
				<text class="back-text">返回</text>
			</view>
			<text class="header-title">告警详情</text>
			<view class="header-right" @click="showMoreActions">
				<uni-icons type="more" size="24" color="#2c3e50"></uni-icons>
			</view>
		</view>
		
		<!-- 加载状态 -->
		<view v-if="loading" class="loading-container">
			<uni-load-more status="loading" content-text="{ contentText: { contentdown: '加载中...', contentrefresh: '加载中...', contentnomore: '加载中...' } }"></uni-load-more>
		</view>
		
		<!-- 错误状态 -->
		<view v-else-if="error" class="error-container">
			<uni-icons type="info" size="48" color="#e74c3c"></uni-icons>
			<text class="error-text">{{ error }}</text>
			<button class="retry-btn" @click="loadAlertDetail">重试</button>
		</view>
		
		<!-- 告警基本信息 -->
		<view v-else class="alert-info" :class="`level-${alertData.level}`">
			<view class="alert-header">
				<view class="alert-level" :class="alertData.level">
					<text class="level-text">{{ getLevelText(alertData.level) }}</text>
				</view>
				<view class="alert-status" :class="getStatusClass(alertData.status)">
					<text>{{ getStatusText(alertData.status) }}</text>
				</view>
			</view>
			<view class="alert-content-wrapper">
				<view class="alert-content-left">
					<text class="alert-title">{{ alertData.title }}</text>
					<text class="alert-desc">{{ alertData.description }}</text>
				</view>
				<view class="alert-content-right">
					<view class="meta-item">
						<uni-icons type="calendar" size="16" color="#7f8c8d"></uni-icons>
						<text class="meta-text">{{ formatDateTime(alertData.time) }}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 告警数据 -->
		<view class="data-section">
			<text class="section-title">告警数据</text>
			<view class="data-grid">
				<view class="data-item" v-for="(item, index) in alertData.data" :key="index">
					<view class="data-row">
						<view class="data-label">{{ item.label }}</view>
						<view class="data-value">{{ item.value }}{{ item.unit }}</view>
					</view>
					<view class="data-row">
						<view class="data-threshold-label">阈值:</view>
						<view class="data-threshold-value">{{ item.threshold }}</view>
					</view>
				</view>
				<!-- 如果没有数据，显示测试数据 -->
				<view class="data-item" v-if="!alertData.data || alertData.data.length === 0">
					<view class="data-row">
						<view class="data-label">浊度</view>
						<view class="data-value">3000.0000NTU</view>
					</view>
					<view class="data-row">
						<view class="data-threshold-label">阈值:</view>
						<view class="data-threshold-value"><3000 NTU</view>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 处理记录 -->
		<view class="process-section">
			<text class="section-title">处理记录</text>
			<view v-if="processRecords.length > 0" class="process-timeline">
				<view class="timeline-item" v-for="(record, index) in processRecords" :key="index">
					<view class="timeline-dot" :class="record.type"></view>
					<view class="timeline-content">
						<text class="timeline-title">{{ record.title }}</text>
						<text class="timeline-desc">{{ record.description }}</text>
						<text class="timeline-time">{{ formatTime(record.time) }}</text>
					</view>
				</view>
			</view>
			<view v-else class="empty-state">
				<uni-icons type="info" size="48" color="#bdc3c7"></uni-icons>
				<text class="empty-text">暂无处理记录</text>
			</view>
		</view>
		
		<!-- 相关设备 -->
		<view class="device-section">
			<text class="section-title">相关设备</text>
			<view class="device-list">
				<view class="device-item" 
					v-for="(device, index) in relatedDevices" 
					:key="index"
					:class="{ 'current-alert-device': device.isCurrentAlert }">
					<view class="device-icon" :class="device.status">
						<uni-icons :type="device.icon" size="20" color="#ffffff"></uni-icons>
					</view>
					<view class="device-info">
						<text class="device-name">
							{{ device.name }}
							<text v-if="device.isCurrentAlert" class="current-alert-badge">当前告警</text>
						</text>
						<text class="device-location">{{ device.location }}</text>
					</view>
					<view class="device-status" :class="device.status">
						<text>{{ getDeviceStatusText(device.status) }}</text>
					</view>
				</view>
			</view>
		</view>
		
		<!-- 操作按钮 -->
		<view class="action-section">
			<!-- 未处理状态：只显示确认按钮 -->
			<button class="btn-confirm" @click="confirmAlert" v-if="alertData.status === 1">
				<text class="btn-title">确认告警</text>
			</button>
			
			<!-- 已确认状态：显示处理按钮 -->
			<button class="btn-primary" @click="handleAlert" v-if="alertData.status === 2">
				<uni-icons type="gear" size="16" color="#ffffff"></uni-icons>
				<text>处理告警</text>
			</button>
			
			<!-- 已处理状态：显示关闭按钮 -->
			<button class="btn-danger" @click="closeAlert" v-if="alertData.status === 3">
				<uni-icons type="close" size="16" color="#ffffff"></uni-icons>
				<text>关闭告警</text>
			</button>
		</view>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { getAlertDetail, updateAlertStatus, getProcessRecords, addProcessRecord } from '@/api/alert.js'

// 响应式数据
const alertData = ref({
	id: '',
	title: '',
	description: '',
	device: '',
	time: new Date(),
	level: 'low',
	status: 1,
	data: []
})

// 页面参数
const alertId = ref('')
const loading = ref(false)
const error = ref('')

const processRecords = ref([])

const relatedDevices = ref([])

// 页面加载
onMounted(() => {
	// 获取URL参数中的告警ID
	const pages = getCurrentPages()
	const currentPage = pages[pages.length - 1]
	const options = currentPage.options
	alertId.value = options.id || ''
	
	if (alertId.value) {
		loadAlertDetail()
	} else {
		error.value = '告警ID不能为空'
		uni.showToast({
			title: '告警ID不能为空',
			icon: 'none'
		})
	}
})

// 加载告警详情
const loadAlertDetail = async () => {
	if (!alertId.value) return
	
	try {
		loading.value = true
		error.value = ''
		
		console.log('📡 加载告警详情:', alertId.value)
		console.log('📡 请求URL:', `/Alert/detail/${alertId.value}`)
		
		const response = await getAlertDetail(alertId.value)
		console.log('📡 后端响应:', response)
		
		if (response && response.code === 200 && response.data) {
			const data = response.data
			console.log('✅ 获取告警详情成功:', data)
			console.log('🔍 关键字段检查 - indicatorCode:', data.indicatorCode, 'currentValue:', data.currentValue, 'normalRange:', data.normalRange)
			
			// 映射后端数据到前端格式
			const formattedData = formatAlertData(data)
			console.log('🔍 格式化后的告警数据:', formattedData)
			
			alertData.value = {
				id: data.alertId || alertId.value,
				title: translateIndicatorTitle(data.title || '告警详情'),
				description: translateIndicatorDescription(data.description || '暂无描述'),
				device: data.device || 'ESP8266_001',
				time: data.createTime ? new Date(data.createTime) : new Date(),
				level: mapSeverityToLevel(data.severity),
				status: data.status || 1,
				data: formattedData
			}
			
			console.log('🔍 最终alertData.value:', alertData.value)
			
			// 处理后端返回的相关设备数据
			if (data.relatedDevices && Array.isArray(data.relatedDevices)) {
				relatedDevices.value = data.relatedDevices.map(device => ({
					deviceId: device.deviceId,
					deviceCode: device.deviceCode,
					name: device.name || device.deviceCode || 'ESP8266_001',
					location: device.location || '河北省保定市莲池区',
					status: getDeviceStatusFromCode(device.statusCode),
					statusCode: device.statusCode,
					icon: device.icon || 'location',
					isCurrentAlert: device.isCurrentAlert || false
				}))
				console.log('📱 处理后端相关设备数据:', relatedDevices.value)
			} else {
				// 如果没有相关设备数据，使用默认数据
				relatedDevices.value = getDefaultRelatedDevices()
				console.log('📱 使用默认相关设备数据')
			}
			
			console.log('✅ 告警数据映射完成:', alertData.value)
			
			// 加载处理记录
			await loadProcessRecords(alertId.value)
			
		} else {
			error.value = response?.msg || '获取告警详情失败'
			console.error('❌ 获取告警详情失败:', response)
			uni.showToast({
				title: error.value,
				icon: 'none',
				duration: 3000
			})
		}
	} catch (err) {
		console.error('❌ 加载告警详情失败:', err)
		error.value = err.message || '网络错误'
		uni.showToast({
			title: '加载失败: ' + error.value,
			icon: 'none',
			duration: 3000
		})
	} finally {
		loading.value = false
	}
}

// 加载处理记录
const loadProcessRecords = async (alertId) => {
	try {
		console.log('📋 加载处理记录，告警ID:', alertId)
		
		const response = await getProcessRecords(alertId)
		console.log('📋 处理记录响应:', response)
		
		if (response && response.code === 200 && response.data) {
			// 转换后端数据格式为前端需要的格式，使用数据库中的具体时间
			processRecords.value = response.data.map(record => {
				// 确保时间格式正确，优先使用数据库中的时间
				let recordTime
				if (record.time) {
					// 如果后端返回的是字符串时间，转换为Date对象
					recordTime = new Date(record.time)
				} else if (record.createTime) {
					// 如果后端返回的是createTime字段
					recordTime = new Date(record.createTime)
				} else {
					// 如果没有时间信息，使用当前时间
					recordTime = new Date()
				}
				
				return {
					type: record.type,
					title: record.title,
					description: record.description,
					time: recordTime
				}
			})
			
			console.log('✅ 处理记录加载成功，使用数据库时间:', processRecords.value)
		} else {
			console.log('⚠️ 处理记录响应异常:', response)
			// 清空处理记录，不显示任何数据
			processRecords.value = []
		}
		
	} catch (error) {
		console.error('❌ 加载处理记录失败:', error)
		// 清空处理记录，不显示任何数据
		processRecords.value = []
	}
}

// 获取默认处理记录（当后端数据不可用时）
const getDefaultProcessRecords = () => {
	return [
		{
			type: 'create',
			title: '告警创建',
			description: '系统检测到设备离线，自动创建告警',
			time: new Date(Date.now() - 1800000)
		},
		{
			type: 'assign',
			title: '分配处理',
			description: '告警已分配给技术员张三处理',
			time: new Date(Date.now() - 1200000)
		},
		{
			type: 'confirm',
			title: '确认告警',
			description: '技术员已确认告警，正在前往现场',
			time: new Date(Date.now() - 600000)
		}
	]
}

// 返回上一页
const goBack = () => {
	uni.navigateBack()
}

// 显示更多操作
const showMoreActions = () => {
	uni.showActionSheet({
		itemList: ['转发告警', '导出数据', '添加备注', '删除告警'],
		success: (res) => {
			console.log('选择操作:', res.tapIndex)
		}
	})
}

// 确认告警
const confirmAlert = async () => {
	uni.showModal({
		title: '确认告警',
		content: '确定要确认此告警吗？',
		success: async (res) => {
			if (res.confirm) {
				try {
					// 调用后端API更新状态
					const response = await updateAlertStatus(alertId.value, 2, 'current_user')
					if (response && response.code === 200) {
						alertData.value.status = 2
						
						// 添加处理记录
						await addProcessRecord(alertId.value, 2, '技术员已确认告警，正在前往现场')
						
						// 重新加载处理记录
						await loadProcessRecords(alertId.value)
						
						uni.showToast({
							title: '确认成功',
							icon: 'success'
						})
					} else {
						uni.showToast({
							title: '确认失败',
							icon: 'none'
						})
					}
				} catch (error) {
					console.error('确认告警失败:', error)
					uni.showToast({
						title: '确认失败',
						icon: 'none'
					})
				}
			}
		}
	})
}

// 处理告警
const handleAlert = async () => {
	uni.showModal({
		title: '处理告警',
		content: '确定要处理此告警吗？',
		success: async (res) => {
			if (res.confirm) {
				try {
					// 调用后端API更新状态
					const response = await updateAlertStatus(alertId.value, 3, 'current_user')
					if (response && response.code === 200) {
						alertData.value.status = 3
						
						// 添加处理记录
						await addProcessRecord(alertId.value, 3, '警告已解决')
						
						// 重新加载处理记录
						await loadProcessRecords(alertId.value)
						
						uni.showToast({
							title: '处理成功',
							icon: 'success'
						})
					} else {
						uni.showToast({
							title: '处理失败',
							icon: 'none'
						})
					}
				} catch (error) {
					console.error('处理告警失败:', error)
					uni.showToast({
						title: '处理失败',
						icon: 'none'
					})
				}
			}
		}
	})
}

// 关闭告警
const closeAlert = async () => {
	uni.showModal({
		title: '关闭告警',
		content: '确定要关闭此告警吗？',
		success: async (res) => {
			if (res.confirm) {
				try {
					uni.showToast({
						title: '关闭成功',
						icon: 'success'
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
				} catch (error) {
					console.error('关闭告警失败:', error)
					uni.showToast({
						title: '关闭失败',
						icon: 'none'
					})
				}
			}
		}
	})
}

// 翻译指标标题
const translateIndicatorTitle = (title) => {
	const indicatorMap = {
		'TEMP': '温度',
		'TEMPERATURE': '温度',
		'TURBIDITY': '浊度',
		'PH': 'pH值'
	}
	
	// 如果标题包含指标代码，则替换为中文
	for (const [code, chinese] of Object.entries(indicatorMap)) {
		if (title.includes(code)) {
			return title.replace(code, chinese)
		}
	}
	
	return title
}

// 翻译指标描述
const translateIndicatorDescription = (description) => {
	const indicatorMap = {
		'TEMP': '温度',
		'TEMPERATURE': '温度',
		'TURBIDITY': '浊度',
		'PH': 'pH值'
	}
	
	// 如果描述包含指标代码，则替换为中文
	for (const [code, chinese] of Object.entries(indicatorMap)) {
		if (description.includes(code)) {
			description = description.replace(code, chinese)
		}
	}
	
	// 在"超出正常范围"前添加换行
	if (description.includes('超出正常范围')) {
		description = description.replace('超出正常范围', '\n超出正常范围')
	}
	
	return description
}

// 映射严重程度到告警级别
const mapSeverityToLevel = (severity) => {
	if (typeof severity === 'number') {
		const levelMap = {
			1: 'low',
			2: 'medium', 
			3: 'high'
		}
		return levelMap[severity] || 'low'
	}
	
	const levelMap = {
		'low': 'low',
		'medium': 'medium',
		'high': 'high'
	}
	return levelMap[severity] || 'low'
}

// 格式化告警数据
const formatAlertData = (data) => {
	const dataArray = []
	console.log('🔍 格式化告警数据，输入数据:', data)
	
	// 临时硬编码数据用于测试
	if (!data.indicatorCode || data.currentValue === undefined) {
		console.log('⚠️ 使用临时测试数据')
		dataArray.push({
			label: '浊度',
			value: '3000.0000',
			unit: 'NTU',
			threshold: '<3000 NTU'
		})
		return dataArray
	}
	
	if (data.indicatorCode && data.currentValue !== undefined) {
		// 映射指标代码到中文名称 - 只保留温度、浊度、pH值
		const indicatorMap = {
			'TEMP': '温度',
			'TEMPERATURE': '温度',
			'TURBIDITY': '浊度',
			'PH': 'pH值'
		}
		
		const chineseName = indicatorMap[data.indicatorCode] || data.indicatorCode
		const unit = getIndicatorUnit(data.indicatorCode)
		
		dataArray.push({
			label: chineseName,
			value: data.currentValue,
			unit: unit,
			threshold: data.normalRange || '正常范围'
		})
		console.log('✅ 格式化后的数据:', dataArray)
	} else {
		console.log('❌ 数据格式不正确，indicatorCode:', data.indicatorCode, 'currentValue:', data.currentValue)
	}
	
	return dataArray
}

// 获取指标单位
const getIndicatorUnit = (indicator) => {
	const unitMap = {
		'TEMP': '°C',
		'TEMPERATURE': '°C',
		'TURBIDITY': 'NTU',
		'PH': '',
		'DO': 'mg/L',
		'DISSOLVED_OXYGEN': 'mg/L',
		'COD': 'mg/L',
		'BOD': 'mg/L',
		'NH3_N': 'mg/L',
		'TP': 'mg/L',
		'TN': 'mg/L',
		'SS': 'mg/L',
		'CONDUCTIVITY': 'μS/cm',
		'ORP': 'mV',
		'CHLORINE': 'mg/L'
	}
	return unitMap[indicator] || ''
}

// 获取告警级别文本
const getLevelText = (level) => {
	const levelMap = {
		low: '低',
		medium: '中',
		high: '高'
	}
	return levelMap[level] || '低'
}

// 获取状态文本
const getStatusText = (status) => {
	const statusMap = {
		1: '未处理',
		2: '已确认',
		3: '已处理'
	}
	return statusMap[status] || '正常'
}

// 获取状态样式类名
const getStatusClass = (status) => {
	const statusMap = {
		1: 'unhandled',
		2: 'confirmed',
		3: 'handled'
	}
	return statusMap[status] || 'unhandled'
}

// 获取设备状态文本
const getDeviceStatusText = (status) => {
	const statusMap = {
		online: '在线',
		offline: '离线',
		fault: '故障'
	}
	return statusMap[status] || '正常'
}

// 格式化日期时间
const formatDateTime = (time) => {
	const date = new Date(time)
	const year = date.getFullYear()
	const month = (date.getMonth() + 1).toString().padStart(2, '0')
	const day = date.getDate().toString().padStart(2, '0')
	const hours = date.getHours().toString().padStart(2, '0')
	const minutes = date.getMinutes().toString().padStart(2, '0')
	return `${year}-${month}-${day} ${hours}:${minutes}`
}

// 格式化时间
const formatTime = (time) => {
	const date = new Date(time)
	const year = date.getFullYear()
	const month = (date.getMonth() + 1).toString().padStart(2, '0')
	const day = date.getDate().toString().padStart(2, '0')
	const hours = date.getHours().toString().padStart(2, '0')
	const minutes = date.getMinutes().toString().padStart(2, '0')
	return `${year}-${month}-${day} ${hours}:${minutes}`
}

// 根据状态代码获取设备状态
const getDeviceStatusFromCode = (statusCode) => {
	const statusMap = {
		1: 'online',
		2: 'offline', 
		3: 'fault'
	}
	return statusMap[statusCode] || 'unknown'
}

// 获取默认相关设备数据
const getDefaultRelatedDevices = () => {
	return [
		{
			deviceId: 1,
			deviceCode: 'ESP8266_001',
			name: 'ESP8266_001',
			location: '河北省保定市莲池区',
			status: 'online',
			statusCode: 1,
			icon: 'location',
			isCurrentAlert: true
		}
	]
}

// 去除"监测点"前缀
const removeMonitoringPointPrefix = (deviceText) => {
	if (!deviceText) return 'ESP8266_001'
	
	// 如果包含"监测点"前缀，则去除
	if (deviceText.startsWith('监测点')) {
		return deviceText.replace('监测点', '')
	}
	
	return deviceText
}
</script>

<style lang="scss" scoped>
.container {
	height: 100vh;
	display: flex;
	flex-direction: column;
	background: #f5f7fa;
}

.header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 30rpx;
	background: #ffffff;
	border-bottom: 1rpx solid #e5e5e5;
	box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.header-left {
	display: flex;
	align-items: center;
	gap: 10rpx;
}

.back-text {
	font-size: 28rpx;
	color: #2c3e50;
}

.header-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #2c3e50;
}

.header-right {
	padding: 10rpx;
}

.alert-info {
	background: #ffffff;
	margin: 20rpx;
	padding: 30rpx 30rpx 20rpx 30rpx;
	border-radius: 12rpx;
	box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
	border-left: 6rpx solid #e74c3c;
	border-right: 6rpx solid #e74c3c;
	
	&.level-low {
		border-left-color: #27ae60;
		border-right-color: #27ae60;
	}
	
	&.level-medium {
		border-left-color: #e67e22;
		border-right-color: #e67e22;
	}
	
	&.level-high {
		border-left-color: #e74c3c;
		border-right-color: #e74c3c;
	}
}

.alert-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 20rpx;
}

.alert-level {
	padding: 8rpx 16rpx;
	border-radius: 20rpx;
	font-weight: bold;
	
	&.low {
		background: #d5f4e6;
		color: #27ae60;
	}
	
	&.medium {
		background: #fff3e0;
		color: #e67e22;
	}
	
	&.high {
		background: #ffebee;
		color: #e74c3c;
	}
}

.level-text {
	font-size: 20rpx;
	font-weight: bold;
}

.alert-status {
	padding: 6rpx 12rpx;
	border-radius: 15rpx;
	font-weight: bold;
	
	&.unhandled {
		background: #ffebee;
		color: #e74c3c;
	}
	
	&.confirmed {
		background: #fff3e0;
		color: #e67e22;
	}
	
	&.handled {
		background: #d5f4e6;
		color: #27ae60;
	}
}

.alert-title {
	font-size: 32rpx;
	font-weight: bold;
	color: #2c3e50;
	margin-bottom: 15rpx;
	display: block;
}

.alert-content-wrapper {
	display: flex;
	flex-direction: column;
	margin-bottom: 0;
}

.alert-content-left {
	margin-bottom: 0;
}

.alert-content-right {
	display: flex;
	justify-content: flex-end;
	align-items: center;
	margin-top: 15rpx;
	margin-bottom: 10rpx;
}

.alert-desc {
	font-size: 26rpx;
	color: #7f8c8d;
	line-height: 1.6;
	margin-bottom: 0;
	display: block;
	white-space: pre-line;
}

.alert-meta {
	display: flex;
	flex-direction: column;
	gap: 10rpx;
}

.meta-item {
	display: flex;
	align-items: center;
	gap: 10rpx;
}

.meta-text {
	font-size: 24rpx;
	color: #7f8c8d;
}

.data-section {
	background: #ffffff;
	margin: 0 20rpx 20rpx;
	padding: 30rpx;
	border-radius: 12rpx;
	box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
}

.process-section, .device-section {
	background: #ffffff;
	margin: 0 20rpx 20rpx;
	padding: 30rpx;
	border-radius: 12rpx;
	box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.08);
}

.section-title {
	font-size: 28rpx;
	font-weight: bold;
	color: #2c3e50;
	margin-bottom: 20rpx;
	display: block;
}

.data-grid {
	display: flex;
	flex-direction: column;
	gap: 8rpx;
}

.data-item {
	background: #f8f9fa;
	padding: 20rpx;
	border-radius: 8rpx;
	border-left: 3rpx solid #3498db;
	display: flex;
	flex-direction: column;
	gap: 12rpx;
}

.data-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.data-label {
	font-size: 22rpx;
	color: #7f8c8d;
	font-weight: 500;
}

.data-value {
	font-size: 24rpx;
	font-weight: 600;
	color: #2c3e50;
}

.data-threshold-label {
	font-size: 22rpx;
	color: #7f8c8d;
	font-weight: 500;
}

.data-threshold-value {
	font-size: 22rpx;
	color: #2c3e50;
	font-weight: 500;
}

.process-timeline {
	position: relative;
}

.timeline-item {
	display: flex;
	margin-bottom: 30rpx;
	position: relative;
	
	&:last-child {
		margin-bottom: 0;
	}
	
	&::before {
		content: '';
		position: absolute;
		left: 20rpx;
		top: 40rpx;
		bottom: -30rpx;
		width: 2rpx;
		background: #e5e5e5;
	}
	
	&:last-child::before {
		display: none;
	}
}

.timeline-dot {
	width: 40rpx;
	height: 40rpx;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: 20rpx;
	z-index: 1;
	
	&.create {
		background: #e74c3c; /* 红色 - 创建警告 */
	}
	
	&.assign {
		background: #f39c12; /* 黄橙色 - 确定警告 */
	}
	
	&.confirm {
		background: #f39c12; /* 黄橙色 - 确认警告 */
	}
	
	&.handle {
		background: #27ae60; /* 绿色 - 处理警告 */
	}
	
	&.close {
		background: #95a5a6; /* 灰色 - 关闭警告 */
	}
}

.timeline-content {
	flex: 1;
}

.timeline-title {
	font-size: 26rpx;
	font-weight: bold;
	color: #2c3e50;
	margin-bottom: 8rpx;
	display: block;
}

.timeline-desc {
	font-size: 24rpx;
	color: #7f8c8d;
	margin-bottom: 8rpx;
	display: block;
}

.timeline-time {
	font-size: 20rpx;
	color: #95a5a6;
}

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 60rpx 20rpx;
	text-align: center;
}

.empty-text {
	font-size: 24rpx;
	color: #95a5a6;
	margin-top: 20rpx;
}

.device-list {
	display: flex;
	flex-direction: column;
	gap: 15rpx;
}

.device-item {
	display: flex;
	align-items: center;
	padding: 20rpx;
	background: #f8f9fa;
	border-radius: 8rpx;
	transition: all 0.3s;
	
	&.current-alert-device {
		background: #fff3e0;
		border: 2rpx solid #ff9800;
		box-shadow: 0 2rpx 8rpx rgba(255, 152, 0, 0.2);
	}
}

.device-icon {
	width: 50rpx;
	height: 50rpx;
	border-radius: 8rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-right: 20rpx;
	
	&.online {
		background: #27ae60;
	}
	
	&.offline {
		background: #95a5a6;
	}
	
	&.fault {
		background: #e74c3c;
	}
}

.device-info {
	flex: 1;
}

.device-name {
	font-size: 26rpx;
	font-weight: bold;
	color: #2c3e50;
	margin-bottom: 5rpx;
	display: block;
	position: relative;
}

.current-alert-badge {
	background: #ff9800;
	color: #ffffff;
	font-size: 18rpx;
	padding: 4rpx 8rpx;
	border-radius: 10rpx;
	margin-left: 10rpx;
	font-weight: bold;
}

.device-location {
	font-size: 22rpx;
	color: #7f8c8d;
}

.device-status {
	padding: 6rpx 12rpx;
	border-radius: 15rpx;
	font-size: 20rpx;
	font-weight: bold;
	
	&.online {
		background: #d5f4e6;
		color: #27ae60;
	}
	
	&.offline {
		background: #f8f9fa;
		color: #95a5a6;
	}
	
	&.fault {
		background: #fadbd8;
		color: #e74c3c;
	}
}

.action-section {
	display: flex;
	flex-direction: column;
	gap: 20rpx;
	padding: 30rpx;
	background: #ffffff;
	margin-top: auto;
	box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.1);
}

.btn-confirm {
	width: calc(100% - 60rpx);
	height: 100rpx;
	background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
	border-radius: 16rpx;
	border: none;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 30rpx;
	position: relative;
	overflow: hidden;
	box-shadow: 0 6rpx 20rpx rgba(39, 174, 96, 0.3);
	transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
	margin: 0 30rpx;
	
	&:active {
		transform: translateY(1rpx) scale(0.98);
		box-shadow: 0 3rpx 12rpx rgba(39, 174, 96, 0.4);
	}
	
	&:hover {
		transform: translateY(-2rpx);
		box-shadow: 0 12rpx 35rpx rgba(39, 174, 96, 0.5);
	}
}

.btn-confirm .btn-title {
	font-size: 32rpx !important;
	font-weight: 700 !important;
	color: #ffffff !important;
	text-shadow: 0 2rpx 4rpx rgba(0, 0, 0, 0.2) !important;
	letter-spacing: 1rpx !important;
	line-height: 1.2 !important;
}

.btn-primary, .btn-secondary, .btn-danger {
	width: calc(100% - 60rpx);
	height: 100rpx;
	border-radius: 16rpx;
	font-size: 32rpx;
	border: none;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10rpx;
	font-weight: bold;
	transition: all 0.3s;
	margin: 0 30rpx;
}

.btn-primary {
	background: #3498db;
	color: #ffffff;
	box-shadow: 0 6rpx 20rpx rgba(52, 152, 219, 0.3);
}

.btn-secondary {
	background: #f8f9fa;
	color: #2c3e50;
	border: 2rpx solid #e9ecef;
	box-shadow: 0 6rpx 20rpx rgba(0, 0, 0, 0.1);
}

.btn-danger {
	background: #e74c3c;
	color: #ffffff;
	box-shadow: 0 6rpx 20rpx rgba(231, 76, 60, 0.3);
}

.loading-container {
	display: flex;
	justify-content: center;
	align-items: center;
	padding: 100rpx 0;
}

.error-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 100rpx 40rpx;
	text-align: center;
}

.error-text {
	font-size: 28rpx;
	color: #7f8c8d;
	margin: 20rpx 0 40rpx;
}

.retry-btn {
	background: #3498db;
	color: #ffffff;
	border: none;
	border-radius: 8rpx;
	padding: 20rpx 40rpx;
	font-size: 26rpx;
}
</style>
